﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;

namespace Project_Udrinkwater.Report_Admin
{
    public partial class ShoeSalaryReport : System.Web.UI.Page
    {
        string Connection = ConfigurationManager.ConnectionStrings["DB_Udrink"].ConnectionString;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
            }
            else
            {
                string Mounth = CB_MonthSelect.Value.ToString();
                string Year = (Convert.ToInt32(CB_YearSelect.Value.ToString()) - 543).ToString();
                SqlConnection objConn = new SqlConnection();
                SqlCommand objCmd = new SqlCommand();
                SqlDataAdapter dtAdapter = new SqlDataAdapter();

                DataSet ds = new DataSet();
                DataTable dt = null;
                string strConnString = null;
                StringBuilder strSQL = new StringBuilder();

                strSQL.Append(" SELECT TB_Employee.Employee_ID,TB_Employee.Prefix,TB_Employee.FirstName,TB_Employee.LastName,TB_Department.Department_Name, ");
                strSQL.Append(" TB_Employee.Salary,TB_Salary.Reduce_Absence,TB_Salary.Reduce_Withdraw,TB_Salary.Reduce_Other,TB_Salary.Commission,TB_Salary.OT ");
                strSQL.Append(" FROM TB_Employee  ");
                strSQL.Append(" LEFT JOIN TB_Department ON TB_Employee.Departmernt_ID = TB_Department.Department_ID ");
                strSQL.Append(" LEFT JOIN TB_Salary ON TB_Salary.Employee_ID = TB_Employee.Employee_ID ");
                strSQL.Append(" WHERE TB_Salary.Salary_StartMonth = '"+Year+"-"+Mounth+"-01'");

                objConn.ConnectionString = Connection;
                var _with1 = objCmd;
                _with1.Connection = objConn;
                _with1.CommandText = strSQL.ToString();
                _with1.CommandType = CommandType.Text;
                dtAdapter.SelectCommand = objCmd;

                dtAdapter.Fill(ds, "ReportSalary");
                dt = ds.Tables[0];

                dtAdapter = null;
                objConn.Close();
                objConn = null;

                ReportDocument rpt = new ReportDocument();
                rpt.Load(Server.MapPath("~/Report Admin/ReportSalary.rpt"));
               
                rpt.SetDataSource(dt);
                rpt.SetParameterValue("Month", CB_MonthSelect.SelectedItem.Text);
                rpt.SetParameterValue("Year", CB_YearSelect.Value);
                this.CrystalReportViewer1.ReportSource = rpt;

                
            }
        }
    }
}